package controller;

import entidade.Aluno;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Thais
 */
public class AlunoDataModel extends ListDataModel<Aluno> implements SelectableDataModel<Aluno> {

    public AlunoDataModel() {
    }

    public AlunoDataModel(List<Aluno> data) {
       super(data); 
       System.out.println("construturo");
        
    }

    @Override
    public Aluno getRowData(String rowKey) {
        //In a real app, a more efficient way like a query by rowKey should be implemented to deal with huge data  
 System.out.println("gerrow data");
        
        List<Aluno> alunos = (List<Aluno>) getWrappedData();

        for (Aluno aluno : alunos) {
            if (aluno.getIdAluno().equals(Long.parseLong(rowKey))) {
                System.out.println("Deu");
                return aluno;
                
            }
        }
System.out.println("nao Deu");
        return null;
    }

    @Override
    public Object getRowKey(Aluno aluno) {
        System.out.println("get row key");
        return aluno.getIdAluno();
    }
}
